home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / waitport.c < prev   
C/C++ Source or Header  |  1996-09-12  |  2KB  |  81 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: waitport.c,v 1.4 1996/08/13 13:56:10 digulla Exp $
  4.     $Log: waitport.c,v $
  5.     Revision 1.4  1996/08/13 13:56:10  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:22  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include "exec_intern.h"
  17. #include <exec/ports.h>
  18. #include <aros/libcall.h>
  19.  
  20. /*****************************************************************************
  21.  
  22.     NAME */
  23.     #include <clib/exec_protos.h>
  24.  
  25.     __AROS_LH1(struct Message *, WaitPort,
  26.  
  27. /*  SYNOPSIS */
  28.     __AROS_LHA(struct MsgPort *, port, A0),
  29.  
  30. /*  LOCATION */
  31.     struct ExecBase *, SysBase, 64, Exec)
  32.  
  33. /*  FUNCTION
  34.     Wait until a message arrives at the given port. If there is already
  35.     a message in it this function returns immediately.
  36.  
  37.     INPUTS
  38.     port    - Pointer to messageport.
  39.  
  40.     RESULT
  41.     Pointer to the first message that arrived at the port. The message
  42.     is _not_ removed from the port. GetMsg() does this for you.
  43.  
  44.     NOTES
  45.  
  46.     EXAMPLE
  47.  
  48.     BUGS
  49.  
  50.     SEE ALSO
  51.     WaitPort(), GetMsg()
  52.  
  53.     INTERNALS
  54.  
  55.     HISTORY
  56.  
  57. ******************************************************************************/
  58. {
  59.     __AROS_FUNC_INIT
  60.  
  61.     /*
  62.     No Disable() necessary here since emptiness can be checked
  63.     without and nobody is allowed to change the signal bit as soon
  64.     as the current task entered WaitPort() (and probably did not yet
  65.     have a chance to Disable()).
  66.     */
  67.  
  68.     /* Is messageport empty? */
  69.     while(port->mp_MsgList.lh_Head->ln_Succ==NULL)
  70.     /*
  71.         Yes. Wait for the signal to arrive. Remember that signals may
  72.         arrive without a message so check again.
  73.     */
  74.     Wait(1<<port->mp_SigBit);
  75.  
  76.     /* Return the first node in the list. */
  77.     return (struct Message *)port->mp_MsgList.lh_Head;
  78.     __AROS_FUNC_EXIT
  79. }
  80.  
  81.